import 'babel-polyfill'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    loginUser: {
      // id: null,
      username: null,
      profile: null,
      unreadMsg: null
      // password: null
    },
    registerUser: {
      username: null,
      phoneNumber: null,
      email: null,
      password: null,
      code: null,
      firstName: null,
      lastName: null,
      sex: null,
      birthDate: null,
      identityNumber: null,
      identityStartDate: null,
      identityEndDate: null,
      identityAddress: null,
      identityCardUrl: null,
      currentAddress: null
    },
    alert: {
      switch: false,
      alertText: ''
    },
    toast: {
      switch: false,
      showType: 'toast',
      toastText: 'aaaaa'
    },
    registerPhone1: null,
    registerPhone2: null
    // phoneNumStatus1: null,
    // phoneNumStatus2: null
  },
  mutations: {
    alert (state, user) {
      state.alert.switch = user.switch
      state.alert.alertText = user.alertText
    },
    toast (state, user) {
      state.toast.switch = user.switch
      state.toast.showType = user.showType
      state.toast.toastText = user.toastText
    },
    updateLoginUser (state, user) {
      // state.loginUser.id = user.id
      state.loginUser.username = user.username
      state.loginUser.profile = user.profile
      state.loginUser.unreadMsg = user.unreadMsg
      // state.loginUser.password = user.password
      // console.log(state)
    },
    clearLoginUser (state) {
      // state.loginUser.id = null
      state.loginUser.username = null
      state.loginUser.profile = null
      state.loginUser.unreadMsg = null
      // state.loginUser.password = null
      // console.log(state)
    },
    updateRegisterUser (state, user) {
      state.registerUser.username = user.username
      state.registerUser.phoneNumber = user.phoneNumber
      state.registerUser.email = user.email
      state.registerUser.password = user.password
      state.registerUser.firstName = user.firstName
      state.registerUser.lastName = user.lastName
      state.registerUser.sex = user.sex
      state.registerUser.birthDate = user.birthDate
      state.registerUser.identityNumber = user.identityNumber
      state.registerUser.identityStartDate = user.identityStartDate
      state.registerUser.identityEndDate = user.identityEndDate
      state.registerUser.identityAddress = user.identityAddress
      state.registerUser.identityCardUrl = user.identityCardUrl
      state.registerUser.currentAddress = user.currentAddress
      console.log(state)
    },
    clearRegisterUser (state) {
      state.registerUser.username = null
      state.registerUser.phoneNumber = null
      state.registerUser.email = null
      state.registerUser.password = null
      state.registerUser.firstName = null
      state.registerUser.lastName = null
      state.registerUser.sex = null
      state.registerUser.birthDate = null
      state.registerUser.identityNumber = null
      state.registerUser.identityStartDate = null
      state.registerUser.identityEndDate = null
      state.registerUser.identityAddress = null
      state.registerUser.identityCardUrl = null
      state.registerUser.currentAddress = null
      console.log(state)
    },
    updateRegisterUserImages (state, images) {
      state.registerUser.images.frontImage = images[0]
      state.registerUser.images.backImage = images[1]
      state.registerUser.images.personImage = images[2]
      console.log(state)
    },
    updateRegisterPhoneNum1 (state, currentNum) {
      state.registerPhone1 = currentNum
    },
    updateRegisterPhoneNum2 (state, currentNum) {
      state.registerPhone2 = currentNum
    }
    // updatePhoneNumStatus1 (state) {
    //   state.phoneNumStatus1 = false
    // },
    // updatePhoneNumStatus2 (state) {
    //   state.phoneNumStatus2 = false
    // }
  }
})

export default store
